package com.suray.attendance.db.utils;

import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;
import java.util.Locale;
import java.util.regex.Pattern;

/**
 * Description: 前端的中国时间转为LocalDate
 * Author: linyu
 * Date: 2023/10/20
 */
public class StringDateToLocalDate {

    public static LocalDate chineConvert(String dateStr) {

        try {

//            dateStr = dateStr.split(Pattern.quote("(中国标准时间)"))[0].replace("GMT+0800", "GMT+08:00");
//            SimpleDateFormat sdf = new SimpleDateFormat("E MMM dd yyyy HH:mm:ss z", Locale.US);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S'Z'");
            Date date = sdf.parse(dateStr);
            Instant instant = date.toInstant();
            ZonedDateTime zonedDateTime = instant.atZone(ZoneId.systemDefault());
            return zonedDateTime.toLocalDate().plusDays(1);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
